package com.chandra.pos.config.security;

import com.chandra.pos.employee.model.EmployeeModel;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;


public class CustomUserBean implements UserDetails {

    // Filed used by UserDetails
    private Collection<? extends GrantedAuthority> grantedAuthorities;


    public CustomUserBean(
            EmployeeModel employee) {
        super();


        this.employee = employee;
    }

    // Field used for custom purpose
    private EmployeeModel employee;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return grantedAuthorities;
    }

    @Override
    public String getPassword() {
        return employee.getPassword();
    }

    @Override
    public String getUsername() {
        return employee.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return !employee.isAccountExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return !employee.isAccountLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return !employee.isCredentialsExpired();
    }

    @Override
    public boolean isEnabled() {
        return employee.isEnabled();
    }

    public EmployeeModel getEmployee() {
        return employee;
    }

    public String getName() {
        return employee.getName();
    }
}
